// pages/storeDetails/storeDetails.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabScrollTop:0,
    tabFixed:false,
    goodsClassTop:0,
    goodsClassFixed:false,
    height:0,
    tabIndex:0,
    classList:[
      {name:'刚刚看过',id:1},
      {name:'热销',id:2},
      {name:'推荐',id:3},
      {name:'优惠',id:4},
      {name:'进店福利',id:5}
    ],
    list:[
      {id:1,title:'汉堡王',img:'../../images/img1.png'},
      {id:1,title:'汉堡王',img:'../../images/img1.png'},
      {id:1,title:'汉堡王',img:'../../images/img1.png'}
    ],
    alllist:[
      {
        classname:'刚刚看过',
        list:[
          {id:1,title:'汉堡王',img:'../../images/img1.png'},
          {id:1,title:'汉堡王',img:'../../images/img1.png'},
          {id:1,title:'汉堡王',img:'../../images/img1.png'}
        ]
      },
      {
        classname:'热销',
        list:[
          {id:1,title:'汉堡王',img:'../../images/img1.png'},
          {id:1,title:'汉堡王',img:'../../images/img1.png'},
          {id:1,title:'汉堡王',img:'../../images/img1.png'}
        ]
      },
      {
        classname:'推荐',
        list:[
          {id:1,title:'汉堡王',img:'../../images/img1.png'},
          {id:1,title:'汉堡王',img:'../../images/img1.png'},
          {id:1,title:'汉堡王',img:'../../images/img1.png'}
        ]
      },
      {
        classname:'优惠',
        list:[
          {id:1,title:'汉堡王',img:'../../images/img1.png'},
          {id:1,title:'汉堡王',img:'../../images/img1.png'},
          {id:1,title:'汉堡王',img:'../../images/img1.png'}
        ]
      },
      {
        classname:'进店福利',
        list:[
          {id:1,title:'汉堡王',img:'../../images/img1.png'},
          {id:1,title:'汉堡王',img:'../../images/img1.png'},
          {id:1,title:'汉堡王',img:'../../images/img1.png'}
        ]
      }
    ],
    classid:'1',
    scrollTopLeft:0,
    scrollTopRight:0,
    topList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var query = wx.createSelectorQuery()
    query.select('.tabs').boundingClientRect(function (res) {
      that.setData({
        tabScrollTop: res.top   //根据实际需求加减值
      })
    }).exec()
    query.select('.all_goods').boundingClientRect(function (res) {
      that.setData({
        goodsClassTop: res.top - 50   //根据实际需求加减值
      })
    }).exec()
    let height = wx.getSystemInfoSync().windowHeight - 40 // 屏幕的高度
    this.setData({
      height:height
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },
  tabChange(e) {
    let index = e.currentTarget.dataset.index
    this.setData({
      tabIndex:index
    })
  },
  goDetails(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/goodsDetails/goodsDetails?id='+id,
    })
  },
  classChange(e) {
    let id = e.currentTarget.dataset.id
    let idx = e.currentTarget.dataset.index
    this.setData({
      classid:id,
      scrollTopRight:this.data.topList[idx]
    })
  },
  onPageScroll(e) {
    if (e.scrollTop > this.data.tabScrollTop) {
      this.setData({
        tabFixed: true
      })
    } else {
      this.setData({
        tabFixed: false
      })
    }
    if (e.scrollTop > this.data.goodsClassTop) {
      this.setData({
        goodsClassFixed: true
      })
      let topList = []
      let view = wx.createSelectorQuery().in(this).selectAll('.alllist_item')
      view.boundingClientRect(data => {
        data.forEach(res1=>{
          let top = res1.top > 0 ? res1.top - 40 : 0
          top = top < 0 ? 0 : top
          topList.push(top)
        })
        this.setData({
          topList:topList
        })
      }).exec();
    } else {
      this.setData({
        goodsClassFixed: false
      })
    }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})